package com.fjp.heartguard.ui.question.fragment

import android.os.Bundle
import android.widget.SeekBar
import androidx.fragment.app.Fragment
import com.fjp.heartguard.app.base.BaseFragment
import com.fjp.heartguard.app.base.HTBaseViewModel
import com.fjp.heartguard.app.data.bean.Questions
import com.fjp.heartguard.app.weight.IndicatorSeekBar
import com.fjp.heartguard.databinding.FragmentSeekbarBinding

class SeekBarFragment : BaseFragment<HTBaseViewModel, FragmentSeekbarBinding>() {


    companion object {
        fun newInstance(questions: Questions?): Fragment {
            val fragment = SeekBarFragment()
            val bundle = Bundle()
            bundle.putSerializable("question", questions)
            fragment.arguments = bundle
            return fragment
        }
    }

    override fun initView(savedInstanceState: Bundle?) {
        val questions = arguments?.getSerializable("question") as Questions?
        questions?.let {
            mDatabind.questionTitleLayout.setType(questions.questionType)
            mDatabind.questionTv.text = it.questionTitle
            if(!questions.options[0].value.isEmpty()){
                mDatabind.seekBar.progress = questions.options[0].value.toInt()
            }else{
                questions.options[0].value = "0"
            }
            mDatabind.seekBar.setOnSeekBarChangeListener(object : IndicatorSeekBar.OnIndicatorSeekBarChangeListener {
                override fun onProgressChanged(seekBar: SeekBar?, progress: Int, indicatorOffset: Float) {
                }

                override fun onStartTrackingTouch(seekBar: SeekBar?) {
                }

                override fun onStopTrackingTouch(seekBar: SeekBar?) {
                    questions.options[0].value = seekBar?.progress.toString()
                }

            })
        }
    }

}